<template>
  <div class="app-container">
    <div class="search-container">
      <el-form :model="searchParam" :inline="true" label-width="94px">
        <SearchFormGroup
          :data="searchParam"
          @change-search="handleSearchChange"
        />
        <el-form-item label="检具名称">
          <el-select
            v-model="searchParam.gageEquipMarkCode"
            placeholder="请选择检具名称"
            clearable
            filterable
          >
            <el-option
              v-for="item in gageEquipList"
              :key="item.toolCode"
              :label="item.toolName"
              :value="item.toolCode"
            />
          </el-select>
        </el-form-item>
        <el-form-item label="特性名称">
          <el-select
            v-model="searchParam.paramId"
            placeholder="请选择特性名称"
            clearable
            filterable
            :disabled="!canSelectSpecific"
           
          >
            <el-option
              v-for="item in specificList"
              :key="item.paramCode"
              :label="item.paramName"
              :value="item.paramId"
            />
          </el-select>
        </el-form-item>

        <el-form-item>
          <el-button type="primary" @click="searchBtn">
            <i-ep-search />
            搜索
          </el-button>
          <el-button @click="resetBtn">
            <i-ep-refresh />
            重置
          </el-button>
          <!-- <el-button type="primary" link @click="collapsed = !collapsed">
            {{ collapsed ? "展开" : "收起" }}
            <i-ep-arrowUp v-if="!collapsed" class="ml-[3px]" />
            <i-ep-arrowDown v-else class="ml-[3px]" />
          </el-button> -->
        </el-form-item>
      </el-form>
    </div>

    <el-card shadow="never" class="table-container">
      <div style="width: 100%" class="m-[10px] pr-[10px]">
        <!-- <div
          style="
            font-size: 20px;
            display: flex;
            justify-content: flex-start;
            margin-bottom: 14px;
          "
        >
          <div style="line-height: 30px">
            <span>Process Capability Analysis</span>
          </div>
        </div> -->

        <div id="printBox" ref="pdfContent" style="position: relative"  v-if="tableData.length>0">
          <img
            src="@/assets/images/logo-icon3.png"
            width="70"
            style="position: absolute; right: 0px; top: -20px"
          />
          <div
            style="
              font-size: 20px;
              display: flex;
              justify-content: flex-start;
              margin-bottom: 8px;
            "
          >
            <div style="line-height: 30px">
              <span>Process Capability Analysis</span>
            </div>
          </div>
        </div>
        <table
          border="1"
          cellpadding="4"
          cellspacing="0"
          align="center"
          style="
            width: 100%;
            border-collapse: collapse; /* 使边框合并为单一边框 */
          "
          v-if="tableData.length>0"
          :style="{
            fontSize: '14px',
            lineHeight: '20px',
            color: '#606266',
          }"
        >
          <colgroup>
            <col width="170" />
            <col width="280" />
            <col width="170" />
            <col width="240" />
            <col width="170" />
            <col width="180" />
          </colgroup>
          <tbody>
            <tr style="border-bottom: 1px solid #606266">
              <td colspan="1">
                <div>
                  <div>Report preview</div>
                  <div>Plant</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>TKPresta cs</div>
                  <div>TK-PD</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Operator Name</div>
                  <div>Calculation method</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>{{ userName }}</div>
                  <div>{{ userName }}</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Date from</div>
                  <div>Date to</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>4/1/2020 3:54:23 PM</div>
                  <div>6/23/2020 3:54:23 PM</div>
                </div>
              </td>
            </tr>
            <tr style="border-bottom: 1px solid #606266">
              <td colspan="1">
                <div>
                  <div>Contract</div>
                  <div>Cost centre</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>&nbsp;</div>
                  <div>&nbsp;</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Customer Number</div>
                  <div>Customer Name</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>{{ searchParam.projectCode }}</div>
                  <div>{{ searchParam.projectName }}</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Part Amend.stat.</div>
                  <div>Plant Sector</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div></div>
                  <div></div>
                </div>
              </td>
            </tr>
            <tr style="border-bottom: 1px solid #606266">
              <td colspan="1">
                <div>
                  <div>Machine Number</div>
                  <div>Mach.Descr.</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>{{ searchParam.equipCode }}</div>
                  <div>{{ searchParam.equipName }}</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Part number</div>
                  <div>Part description</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>{{ searchParam.productCode }}</div>
                  <div>{{ searchParam.productName }}</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>Work Cycle / Operatio</div>
                  <div>Inspector name</div>
                </div>
              </td>
              <td colspan="1">
                <div>
                  <div>9</div>
                  <div>{{ userName }}</div>
                </div>
              </td>
            </tr>

            <tr style="border-bottom: 1px solid #606266">
              <td colspan="1">
                <div>
                  <div>Comment</div>
                </div>
              </td>
              <td colspan="5">
                <div>
                  <div>&nbsp;</div>
                </div>
              </td>
            </tr>
          </tbody>
        </table>
      </div>

      <el-table
        ref="dataTableRef"
        v-loading="loading"
        :data="tableData"
        highlight-current-row
        border
        @selection-change="handleSelectionChange"
        :header-cell-style="{ textAlign: 'center' }"
      >
        <el-table-column
          label="Chart.No"
          type="index"
          width="80"
          align="center"
        />
        <el-table-column
          label="Char.Descr."
          prop="codeForTDDModel"
          min-width="150"
          align="left"
          show-overflow-tooltip
        />
        <el-table-column
          prop="ntot"
          min-width="80"
          align="right"
          show-overflow-tooltip
        >
          <template #header>
            <div class="flex justify-center relative">
              <!-- 父容器添加 position: relative -->
              <span
                style="
                  font-size: 16px;
                  position: relative;
                  display: inline-block;
                "
              >
                n
                <span
                  style="
                    font-size: 11px;
                    position: absolute;
                    bottom: -6px;
                    left: 8px;
                    width: 20px;
                  "
                  >tot</span
                >
              </span>
            </div>
          </template>
          <template #default="scope"> {{ pageable.total }}</template>
        </el-table-column>
        <el-table-column
          prop="n<LSL>"
          min-width="80"
          align="right"
          show-overflow-tooltip
        >
          <template #header>
            <div class="flex justify-center relative">
              <!-- 父容器添加 position: relative -->
              <span
                style="
                  font-size: 16px;
                  position: relative;
                  display: inline-block;
                "
              >
                n
                <span
                  style="
                    font-size: 11px;
                    position: absolute;
                    bottom: -6px;
                    left: 2px;
                    width: 50px;
                  "
                  >{{ '<LSL>' }}</span
                >
              </span>
            </div>
          </template>

          <template #default="scope"> {{ minToatal(scope.row) }}</template>
        </el-table-column>
        <el-table-column
          label="n>USL"
          prop="n>USL"
          min-width="80"
          align="right"
          show-overflow-tooltip
        >
        <template #header>
            <div class="flex justify-center relative">
              <!-- 父容器添加 position: relative -->
              <span
                style="
                  font-size: 16px;
                  position: relative;
                  display: inline-block;
                "
              >
                n
                <span
                  style="
                    font-size: 11px;
                    position: absolute;
                    bottom: -6px;
                    left: 2px;
                    width: 50px;
                  "
                  >{{ '>USL' }}</span
                >
              </span>
            </div>
          </template>
          <template #default="scope"> {{ maxToatal(scope.row) }}</template>
      
      </el-table-column>
        <el-table-column
          label="X̅"
          prop="x"
          min-width="80"
          align="right"
          show-overflow-tooltip
        >
        <template #default="scope"> {{ calculateAverage(scope.row.points).toFixed(5) }}</template>
      </el-table-column>
        <el-table-column
          label="S"
          prop="S"
          min-width="80"
          align="right"
          show-overflow-tooltip
        />
        <el-table-column
          label="index"
          prop="cp"
          min-width="120"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope">
            <div class="flex justify-evenly">
              <div>Cp</div>
              <div>{{ Number(scope.row.cp).toFixed(5) }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="index"
          prop="cpk"
          min-width="120"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope">
            <div class="flex justify-evenly">
              <div>{{ scope.row.cpkDatatype=='1'?'cpk':'ppk' }}</div>
              <div>{{Number(scope.row.cpk).toFixed(6) }}</div>
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="Overall ev"
          prop="ev"
          min-width="100"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope"
            >
            <div>
              <svg-icon
            
                icon-class="face1"
                :size="'25'"
                :color="'#7efa00'"
              />
              <!-- Big(scope.row.cpk).times(1.5) -->
              <svg-icon
                icon-class="face2"
                :size="'23'"
                :color="'red'"
              />
               <svg-icon
                icon-class="face3"
                :size="'23'"
                :color="'red'"
              />
            </div>
            <!-- <div>
              <svg-icon icon-class="face1" />
              <svg-icon icon-class="face2" />
              <svg-icon icon-class="face3" />
            </div> -->
          </template>
        </el-table-column>
        <el-table-column
          label="Value chart Individuals"
          prop="ev"
          min-width="250"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope">
            <div style="height: 100%">
              <reportPointLineChartNew
                :key="Math.random().toString()"
                :id="Math.random().toString()"
                :isPdf="true"
                ref="pcmPointLineChartRef"
                :showName="true"
                :seriesData="scope.row"
              />
            </div>
          </template>
        </el-table-column>
        <el-table-column
          label="Histogram Individuals"
          prop="ev"
          min-width="250"
          align="center"
          show-overflow-tooltip
        >
          <template #default="scope">
            <div style="height: 100%">
              <reportPointBarLineChart
                 :key="Math.random().toString()"
                :id="Math.random().toString()"
                ref="reportPointBarLineChart"
                :showName="true"
              :seriesData="pcmPointBarLineChart(scope.row)"
              />
            </div>
          </template>
        </el-table-column>
      </el-table>

      <el-pagination
        :background="true"
        :current-page="pageable.pageNum"
        :page-size="pageable.pageSize"
        :page-sizes="[10, 25, 50, 100]"
        :total="pageable.total"
        layout="total, sizes, prev, pager, next, jumper"
        class="mt-[20px]"
        @size-change="handleSizeChange"
        @current-change="handleCurrentChange"
      />
    </el-card>

    <pcmmeasurefeatures-edit
      :visible="addDialog.visible"
      :title="addDialog.title"
      :data="addDialog.data"
      @reset-table="(id:string) => (id?.length ? getTableList() : reset())"
      :is-readonly="addDialog.readvisible"
      @change-visible="changeVisible"
    />

    <pcmConfigMeasurementsEdit
      :visible="configMeasurementDialog.visible"
      :title="configMeasurementDialog.title"
      :data="configMeasurementDialog.data"
      :abilityType="configMeasurementDialog.abilityType"
      @reset-table="(id:string) => (id?.length ? getTableList() : reset())"
      :is-readonly="configMeasurementDialog.readvisible"
      @change-visible="changeConfigMeasurementDialogVisible"
    />
  </div>
</template>

<script setup lang="ts">
import { useDictionary, useTable } from "@/utils/useTable";
import request from "@/utils/request";
import { getUserInfo } from "@/api/user/index";
import SearchFormGroup from "@/views/pcm/pcmMonitoring/components/SearchFormGroup.vue";
import {
  getMdminspectiontoolApi,
  getMdmProcessEquipApi,
  getMdmProcessProjectApi,
  getMdmproductinfosApi,
  getMdmprojectinfosApi,
  getSpecificListApi,
  getMdmprocessListApi,
  getMdmProcessEquipApi1,
} from "@/utils/commonData";
import pcmConfigMeasurementsEdit from "@/views/pcm/pcmconfigmeasurements/components/pcmconfigmeasurements-edit.vue";

defineOptions({
  name: "PCMPROCESSCAPABILITYREPORT",
  inheritAttrs: false,
});

// 请求参数
const requestApi = "/dmpDosPcm/pcmtimingpoint/cpkPage";

// 是否需要分页
const pagination = true;

const initParam = {};

// 初始化搜索参数数据
const searchParamInit = {
  processId: "",
  processCode: "",
  processName: "",
  equipId: "",
  equipCode: "",
  equipName: "",
  projectId: "",
  projectCode: "",
  projectName: "",
  modelId: "",
  modelCode: "",
  modelName: "",
  gageEquipId: "",
  gageEquipCode: "",
  gageEquipName: "",
  gageEquipMarkId: "",
  gageEquipMarkCode: "",
  gageEquipMarkName: "",
  paramId: "",
  paramCode: "",
  paramName: "",
  productId: "",
  productCode: "",
 
};

const deleteParam = {
  api: "/dmpDosPcm/pcmmeasurefeatures/delete",
  data: {},
};

// 数据请求错误后处理
function requestError() {}

const dataCallBack = ref(undefined); // 无需二次数据处理&不传赞数也行

// 表格操作 Hooks
const {
  tableData,
  pageable,
  searchParam,
  ids,
  getTableList,
  search,
  reset,
  handleSizeChange,
  handleCurrentChange,
  handleSelectionChange,
  handleTableDelete,
  loading,
}: any = useTable(
  requestApi,
  initParam,
  searchParamInit,
  pagination,
  dataCallBack.value,
  requestError,
  deleteParam
);

// --------------------------------------------------------------------------------------------------------组件 开始
// 处理传回数据
const handleSearchChange = (data) => {
  Object.assign(searchParam.value, data);
  // 可执行字段相关的特定逻辑
};
// --------------------------------------------------------------------------------------------------------组件 结束
const resetBtn = () => {
  reset();
};

const addDialog = reactive<DialogOption>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
});

const configMeasurementDialog = reactive<
  DialogOption & { abilityType: string }
>({
  visible: false,
  readvisible: false,
  title: "",
  data: {},
  abilityType: "",
});

// 查询详情
async function getInfo(id: string) {
  request({
    url: `/dmpDosPcm/pcmmeasurefeatures/get/${id}`,
    method: "get",
  })
    .then((data) => {
      data.data.isRatioUp = data.data.isRatioUp == 1;
      data.data.isRatioDow = data.data.isRatioDow == 1;
      data.data.isSingle = data.data.isSingle == 1;
      data.data.isAverage = data.data.isAverage == 1;
      data.data.isLong = data.data.isLong == 1;
      data.data.isStage = data.data.isStage == 1;
      data.data.isFeatures = data.data.isFeatures == 1;
      data.data.isSingleOrder = data.data.isSingleOrder == 1;
      data.data.isAverageOrder = data.data.isAverageOrder == 1;
      data.data.isLongOrder = data.data.isLongOrder == 1;
      data.data.isStageOrder = data.data.isStageOrder == 1;
      data.data.isFeaturesOrder = data.data.isFeaturesOrder == 1;
      addDialog.data = data.data;
      addDialog.visible = true;
    })
    .catch((res) => {
      console.log(res);
    });
}

/** 打开测量特性定义表单弹窗 */
function openDialog(roleObj?: Object) {
  if (roleObj) {
    addDialog.title = "测量特性-修改";
    getInfo(roleObj.id);
  } else {
    addDialog.title = "测量特性-新增";
    addDialog.visible = true;
  }
  addDialog.readvisible = false;
}

async function synchronous() {
  const { data } = await request({
    url: `/dmpDosPcm/pcmmeasurefeatures/synchronousProgram`,
    method: "post",
  });
  ElMessage.success("同步成功！");
  search();
}

/** 打开测量特性定义表单弹窗 详情 */
function openDialogdetail(roleObj?: any) {
  addDialog.title = "测量特性-详情";
  getInfo(roleObj.id);
  addDialog.readvisible = true;
}

function changeVisible(value: boolean) {
  addDialog.visible = value;
  if (!value) {
    addDialog.data = {};
  }
}

function changeConfigMeasurementDialogVisible(value: boolean) {
  configMeasurementDialog.visible = value;
  if (!value) {
    configMeasurementDialog.data = {};
  }
}

// 搜索项折叠
const collapsed = ref(false);

async function deleteItem(id: any) {
  ElMessageBox.confirm("确认删除已选中的数据项?", "警告", {
    confirmButtonText: "确定",
    cancelButtonText: "取消",
    type: "warning",
  }).then(async () => {
    const { data } = await request({
      url: `/dmpDosPcm/pcmmeasurefeatures/deleteItem/${id}`,
      method: "post",
    });
    search();
  });
}
const userName=ref<string|undefined>('')
onMounted(async() => {
  // 获取table列表
  // getTableList();
  // -----------------------
  // 获取项目列表
  getProjectList({});

  // 获取工序列表
  getProcessList({});

  // 获取设备列表
  getEquipList({});

  // 获取产品型号列表
  getProductList({});

  // // 获取量检具列表
  getGageEquipList({});
  // tableData.value = nn;
  console.log(Math.random().toString());
  await getUserInfo().then(({ data }) => {
    
    userName.value= data.userName;
        
      });
  
});

// 通过工序查询设备列表
const equipList = ref(<any>[]);

async function getEquipList(params: Object) {
  equipList.value = (await getMdmProcessEquipApi1(params)) || [];
}

function equipChange(id: string) {
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  if (id) {
    const current: any =
      equipList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.equipCode = current.equipCode || "";

    getProcessList({ equipId: id });
    getProductList({ equipId: id });
    getProjectList({ equipId: id });
  } else {
    searchParam.value.equipCode = "";
  }
}

// 获取工序列表
const processList = ref<any>([]);

async function getProcessList(params: Object) {
  processList.value = (await getMdmprocessListApi(params)) || [];
}

function processChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  searchParam.value.projectId = "";
  searchParam.value.projectCode = "";
  searchParam.value.projectName = "";

  if (id) {
    const current: any =
      processList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.processCode = current.processCode || "";
    getEquipList({ processId: id });
    getProductList({ processId: id });
    getProjectList({ processId: id });
  } else {
    searchParam.value.processCode = "";
    equipList.value = [];
  }
}

// 获取项目列表
const projectList = ref<any>([]);

async function getProjectList(params: Object) {
  projectList.value = (await getMdmprojectinfosApi(params)) || [];
}

function projectChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  searchParam.value.productId = "";
  searchParam.value.productCode = "";
  if (id) {
    const current: any =
      projectList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.projectCode = current.projectCode || "";
    getEquipList({ projectId: id });
    getProductList({ projectId: id });
    getProcessList({ projectId: id });
  } else {
    searchParam.value.projectCode = "";
    // equipList.value = [];
    // processList.value = [];
    // productList.value = [];
  }
}

// 获取产品型号列表
const productList = ref<any>([]);

async function getProductList(params) {
  productList.value = (await getMdmproductinfosApi(params)) || [];
}

function productChange(id: string) {
  searchParam.value.equipId = "";
  searchParam.value.equipCode = "";
  searchParam.value.projectId = "";
  searchParam.value.projectName = "";
  searchParam.value.projectCode = "";
  searchParam.value.processId = "";
  searchParam.value.processCode = "";
  searchParam.value.processName = "";
  if (id) {
    const current: any =
      productList.value?.filter((e: any) => e.id === id)[0] ?? {};
    searchParam.value.productCode = current.productCode || "";
    getEquipList({ productId: id });
    getProcessList({ productId: id });
    getProjectList({ productId: id });
  } else {
    searchParam.value.productCode = "";
  }
}

// 量检具类型变化
function toolKindChange(type: string) {
  searchParam.value.gageEquipCode = "";
  searchParam.value.gageEquipMarkCode = "";
  if (type) {
    getGageEquipList(type);
  } else {
    gageEquipList.value = [];
  }
}

// 获取量检具列表
const gageEquipList = ref<any>([]);

async function getGageEquipList(params) {
  gageEquipList.value = (await getMdminspectiontoolApi({})) || [];
}

// 获取特性值列表
const specificList = ref<any>([]);

async function getSpecificList() {
  specificList.value =
    (await getSpecificListApi({
      equipId: searchParam.value.equipId,
      gageEquipMarkCode: searchParam.value.gageEquipMarkCode,
      modelId: searchParam.value.productId,
      processId: searchParam.value.processId,
    })) || [];
}

// 检测必填项，筛选特性值列表
const canSelectSpecific = ref(false);
watch(
  () => searchParam.value,
  (newVal) => {
    if (
      newVal.equipCode &&
      newVal.gageEquipMarkCode &&
      newVal.productCode &&
      newVal.processCode
    ) {
      canSelectSpecific.value = true;
      getSpecificList();
    } else {
      canSelectSpecific.value = false;
    }
  },
  {
    deep: true,
  }
);

const getConfigMeasurement = async (programId, abilityType) => {
  await request({
    url: `/dmpDosPcm/pcmconfigmeasurements/getByProgram`,
    method: "get",
    params: { programId, abilityType },
  })
    .then(({ data }) => {
      configMeasurementDialog.data = data ?? { programId, abilityType };
    })
    .catch((res) => {
      console.log(res);
    });
};

const configMeasurement = async (row, abilityType) => {
  configMeasurementDialog.title = "测量特性定义详情";
  configMeasurementDialog.visible = true;
  await getConfigMeasurement(row.id, abilityType);
  configMeasurementDialog.readvisible = false;
  configMeasurementDialog.abilityType = abilityType;
};

// 预警工单 回显
function handleCheckAllChange1(formData: any) {
  if (
    formData.isSingleOrder == 0 &&
    formData.isAverageOrder == 0 &&
    formData.isLongOrder == 0 &&
    formData.isStageOrder == 0 &&
    formData.isFeaturesOrder == 0
  ) {
    return false;
  } else {
    return true;
  }
}

// 预警邮件 回显
function handleCheckAllChange2(formData: any) {
  if (
    formData.isSingle == 0 &&
    formData.isAverage == 0 &&
    formData.isLong == 0 &&
    formData.isStage == 0 &&
    formData.isFeatures == 0
  ) {
    return false;
  } else {
    return true;
  }
}

const searchBtn = () => {
  console.log(searchParam.value);
  
  if (searchParam.value.paramId) {
    search();
  } else {
    ElMessage.warning("请选择特性项！");
  }
};

let nn = [
  {
    charDescr: "Joumal E - Diameter(center)",
    ntot: "125",
    "n<LSL>": "0",
    "n>USL": "0",
    x: 33.99999999,
    S: 0.000567675,
    index1: "1.92",
    type1: "Cp",
    index2: "1.77",
    type2: "Cpk",
    env: "true",
    list1: [],
    list2: [],
  },
];

// 取最大值及最小值

function findMinMax(arr) {
  const min = Math.min(...arr);
  const max = Math.max(...arr);
  return { min, max };
}
 



function createRangeArray(start, end, segments) {
    const step = (end - start) / segments;
    return Array.from({ length: segments }, (_, i) => start + i * step);
}
 
// const result = createRangeArray(1, 2, 12);


const pcmPointBarLineChart=(data)=>{
  const { min, max } = findMinMax(data.points);
  const result = createRangeArray(min, max, 14);
  let mm={
    ydata1:[],
    ydata2:[],
    xdata:[]
  }

  let result1 = [0, 0, 0, 0,0,0,0,0,0,0,0,0,0] // 初始化四个区间的计数器

// 确保 points 是升序排列的
const sortedPoints = [...result].sort((a, b) => a - b)

// 遍历每个数据点
for (const point of data.points) {
  for (let i = 0; i < 14; i++) {
    const start = sortedPoints[i]
    const end = sortedPoints[i + 1]

    // 判断点是否落在当前区间（左闭右开）
    if (point >= start && point < end) {
      result1[i]++
      break // 找到匹配区间后跳出循环
    }
  }
}



 mm.ydata1=result1
 mm.ydata2=result1
 mm.xdata=result

return mm
  // return result
  
}


// // 定义数据源
// const points = ref([10, 20, 30, 40, 50]) // 五个点
// const dataPoints = ref([15, 25, 35, 45, 55]) // 待统计的点

// // 计算属性：统计每个区间内的点数
// const intervalsCount = computed(() => {
//   const result = [0, 0, 0, 0] // 初始化四个区间的计数器

//   // 确保 points 是升序排列的
//   const sortedPoints = [...points.value].sort((a, b) => a - b)

//   // 遍历每个数据点
//   for (const point of dataPoints.value) {
//     for (let i = 0; i < 4; i++) {
//       const start = sortedPoints[i]
//       const end = sortedPoints[i + 1]

//       // 判断点是否落在当前区间（左闭右开）
//       if (point >= start && point < end) {
//         result[i]++
//         break // 找到匹配区间后跳出循环
//       }
//     }
//   }

//   return result
// })







// 小于公差下限
const minToatal=(row)=>{
  let count = row.points.filter(element => element < row.ltl).length;
  return count
}
// 大于公差上限
const maxToatal=(row)=>{
  let count = row.points.filter(element => element > row.utl).length;
  return count
}
// 样本均值

function calculateAverage(arr) {
    if (arr.length === 0) return 0; // 避免除以0的错误
    const sum = arr.reduce((accumulator, currentValue) => accumulator + Number(currentValue), 0);
    return sum / arr.length;
}


// 笑脸
const face1Svg=(item,t)=>{
  if(t=='1'){

  }else if(t=='2'){

  }else if(t=='3'){

  }
}


</script>
<style lang="scss" scoped>
.face_svg {
  font-size: 26px;
  position: absolute;
  right: 0;
  top: 8px;
}
</style>
